package com.liming.common.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @author liming
 * @date 2025/02/04
 **/
public class OrderUtils {

    private static final String orderNoPrefix = "SE";
    private static final String refundOrderNoPrefix = "SER";

    /**
     * 生成订单号，格式为：年月日+随机数
     *
     * @return 订单号
     */
    public static String generateOrderNo() {
        // 获取当前日期，格式为yyyyMMdd
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        String dateStr = dateFormat.format(new Date());

        // 生成一个6位随机数
        Random random = new Random();
        int randomNumber = 100000 + random.nextInt(900000);

        // 组合日期和随机数生成订单号
        return dateStr + String.format("%06d", randomNumber);
    }

    public static String orderNo() {
        return orderNoPrefix + generateOrderNo();
    }

    public static String refundOrderNo() {
        return refundOrderNoPrefix + generateOrderNo();
    }
}
